# pragma once
#include <iostream>

void passByValue(int myNumber);
void passByPointer(int *myNumber);
void passByReference(int &myNumber);
void ShowFunctionsAndPointers() {
    std::cout<< "--- function pointer and reference --- "<<std::endl;

    int mynumber = 10;

    passByValue(mynumber);
    std::cout << "After passByValue: " << mynumber << std::endl; // 输出仍然是 10
    int * myPointer = &mynumber; // 指针指向变量的地址
    passByPointer(myPointer);
    std::cout << "After passByPointer: " << mynumber << std::endl; // 输出仍然是 1
    std::cout<<"myPointer address: "<<myPointer<<std::endl;

    mynumber = 10;
    int& numberRef = mynumber;
    std::cout<<"numberRef address: "<<&numberRef<<std::endl;
    std::cout<<"numberRef value is: "<<numberRef<<std::endl;
// 按照引用传递
    passByReference(numberRef);
    std::cout << "After passByReference: " << mynumber << std::endl; // 输出仍然是 1
   
    int* dynamicNumber = new int(100);
    std::cout<<"dynamicNumber: "<<*dynamicNumber<<std::endl;
    std::cout<<"dynamicNumber address: "<<dynamicNumber<<std::endl;

    delete dynamicNumber; // 释放动态分配的内存
    dynamicNumber = nullptr; 
    
}

void passByPointer(int *myNumber) {
    *myNumber = 1;
}

void passByValue(int myNumber) {
    myNumber = 1;
}

void passByReference(int &myNumber) {
    myNumber = 1;
}